<?php
namespace Home\Controller;
use Common\Controller\BaseController;

class HomeController extends BaseController {

    public $loginStatus;
    public $accountUrl;
    public $userID;
    public $userName;
    public $userType;

    public function _initialize(){
    	parent::_initialize();

    	$userID = cookie('userID');
    	$userName = cookie('userName');
    	$userType = cookie('userType');

    	if(empty ($userName) || empty ($userID) || empty($userType)){ 
    		$this->loginStatus = false;
        }else{
            $this->userID = \Think\Crypt\Driver\Xxtea::decrypt(cookie('userID'),C('cookie_fix'));
            $this->userName = \Think\Crypt\Driver\Xxtea::decrypt(cookie('userName'),C('cookie_fix'));
        	$this->userType = \Think\Crypt\Driver\Xxtea::decrypt(cookie('userType'),C('cookie_fix'));
        	$this->loginStatus = true;
        	if ($this->userType==1) {
        		$this->accountUrl = U('Mentees/index/index');
                $nickname = M('Mentees')->where('userid='.$this->userID)->getField('nickname');
        	}elseif($this->userType==2){
        		$this->accountUrl = U('Mentors/index/index');
                $nickname = M('Mentors')->where('userid='.$this->userID)->getField('nickname');
        	}else{
                $this->accountUrl = U('User/index/index');
                $nickname = M('User')->where('userid='.$this->userID)->getField('nickname');
            }    
            if (!$nickname) {
                $nickname = $this->userName;
            }   	
        }
        $this->assign('loginStatus',$this->loginStatus);
        $this->assign('accountUrl',$this->accountUrl);
        $this->assign('userName',$this->userName);
        $this->assign('nickname',$nickname);
    }
}